package com.itheima.controller;

import com.itheima.common.OssTemplate;
import com.itheima.common.VodTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 文件上传接口
 * @Author: hsp
 * @Date: 2022/11/18-11-18-21:46
 * @Description: com.itheima.controller
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/admin/upload")
public class UploadController {

    @Resource
    private OssTemplate ossTemplate;

    @Resource
    private VodTemplate vodTemplate;

    // 图片上传
    @PostMapping("/image")
    public String uploadImage(MultipartFile uploadImage) throws IOException {
        String imagePath = ossTemplate
                .upload(uploadImage.getOriginalFilename(), uploadImage.getInputStream());

        System.out.println("图片上传之后的访问地址是："+imagePath);
        return imagePath;
    }

    // 视频上传
    @PostMapping("/video")
    public String uploadVideo(MultipartFile uploadVideo) throws IOException {
        String playId = vodTemplate
                .uploadVideo(uploadVideo.getOriginalFilename(), uploadVideo.getInputStream());

        System.out.println("视频上传后的播放id是："+playId);
        return playId;
    }

}
